package com.szpx.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.szpx.entity.HZJ.Announcement;
import com.szpx.mapper.AnnouncementMapper;
import com.szpx.service.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;

@Service
public class AnnouncementServiceImpl implements AnnouncementService {

    @Autowired
    private AnnouncementMapper announcementMapper;

    @Override
    public PageInfo<Announcement> getAnnouncementsByPage(int pageNum, int pageSize, Map<String, Object> params) {
        PageHelper.startPage(pageNum, pageSize);
        List<Announcement> announcements = announcementMapper.findByCondition(params);
        return new PageInfo<>(announcements);
    }

    @Override
    public Announcement getAnnouncementById(Long id) {
        return announcementMapper.findById(id);
    }

    @Override
    public boolean createAnnouncement(Announcement announcement) {
        return announcementMapper.insert(announcement) > 0;
    }

    @Override
    public boolean updateAnnouncement(Announcement announcement) {
        return announcementMapper.update(announcement) > 0;
    }

    @Override
    public boolean deleteAnnouncement(Long id) {
        return announcementMapper.deleteById(id) > 0;
    }
}